//
//  YNDataReading.m
//  Journey
//
//  Created by dllo on 16/5/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YNDataReading.h"

@implementation YNDataReading

//单例
+(YNDataReading *)shareYNataReading{
    static YNDataReading *reading = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        reading = [[YNDataReading alloc]init];
    });
    return reading;
    
}





#pragma mark — 写入缓存
-(void)writeCachePlist:(NSString *)namePlist result:(id)result{
    
    NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    
    NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",namePlist]];
 //   NSLog(@"%@",filePath);
    [result writeToFile:filePath atomically:YES];
    
    
}

#pragma mark — 读取缓存
-(NSDictionary *)readCachePlist:(NSString *)namePlist{
    
    NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    
    NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",namePlist]];
    
    NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
    
    return resultDic;
}


#pragma mark — 读取缓存
-(NSArray *)readPlist:(NSString *)namePlist{
    
    NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    
    NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",namePlist]];
    
    NSArray *resultArr = [NSArray arrayWithContentsOfFile:filePath];
    
    return resultArr;
}

@end
